<?php
require_once(FRAMEWORK_DIR . 'JankController.php');
require_once('CMSParser.php');
require_once(MODEL_DIR . 'Content/ContentFactory.php');
/**
 * DisplayController is an implementation of JankController for the JankCMS 
 * application. It connects to the User and Content models, allowing it
 * to display jankCMS content.
 *
 * @author Rick Hutcheson
 * @version 0.1
 */
class DisplayController extends JankController {
    public $templateDir;
    public function __construct($parameters) {
        // the order of these calls is important. If it is switched, an 
        // attempt to parse will be made before the parser is initialized.
        $this->parser = new CMSParser();
        $this->templateDir = APP_DIR . 'templates/display_templates';
        parent::__construct($parameters);
    }
    
    public function run() {
        $fac = new ContentFactory();
        $content = $fac->getLatestContent(5);
        $html = "";
        foreach ($content as $c) {
            $tags = $c->getTags();
            if(!empty($tags)) {
                $tag = $tags[0];
            } else {
                $tag = "";
            }
            $html .= "<h2>" .$c->getTitle() . "</h2>";
            $html .= "<p>" . $c->getContent() . "</p>";
            $html .= "<p>" . $tag . "</p>";
        }$values['page_content'] = $html;
        $values['section_title'] = "Just some default section";
        $this->display("default"); 
    }
    
    
}
